syntax = "proto3";

import "common.proto";


// Data needs to be sent each time
// Server can't create a Hanlder
// instance without it
message HandlerContext {
    string context = 1;
    string handler_type = 2;
    string handler_params = 3;
}

// Data of 'native_query' request
message NativeQueryContext {
    HandlerContext context = 1;
    string query = 2;
}

// Data of 'query' request
message BinaryQueryContext {
    HandlerContext context = 1;
    bytes query = 2;
}

// Data of 'get_columns' request
message ColumnsContext {
    HandlerContext context = 1;
    string table = 2;
}

// Interface exported by the server.
service DBService {
  // A simple RPC.
  //
  // Establish connection to the specified database
  //
  // by creating an appropriate type of Handler instance
  rpc Connect(HandlerContext) returns (StatusResponse) {}

  // A simple RPC.
  //
  // Check connection to the specified database
  //
  // by creating an appropriate type of Handler instance
  rpc CheckConnection(HandlerContext) returns (StatusResponse) {}

  // A simple RPC.
  //
  // Drop the connection to the specified database
  //
  // by creating an appropriate type of Handler instance
  rpc Disconnect(HandlerContext) returns (StatusResponse) {}

  // A simple RPC.
  //
  // Execute native query (string) and returns the result
  //
  // wrapped into Response object
  rpc NativeQuery(NativeQueryContext) returns (Response) {}

  // A simple RPC.
  //
  // Execute query (object) and returns the result
  //
  // wrapped into Response object
  rpc BinaryQuery(BinaryQueryContext) returns (Response) {}

  // A simple RPC.
  //
  // Performs 'get_tables' request and returns the result
  //
  // wrapped into Response object
  rpc GetTables(HandlerContext) returns (Response) {}

  // A simple RPC.
  //
  // Performs 'get_columns' request and returns the result
  //
  // wrapped into Response object
  rpc GetColumns(ColumnsContext) returns (Response) {}
}
